﻿package org.hsl.avm2.translation.mouse;
import flash.display.DisplayObject;
import flash.geom.Point;
import flash.Lib;
/**
 * The location, the x and the y coordinate, of the mouse, relative to a scope.
 */
class LocalMouseLocation extends MouseLocation {
	/**
	 * The global location of the mouse. The global location is relative to the stage, as opposed to an other scope.
	 */
	public var globalLocation(getGlobalLocation, null):MouseLocation;
	private var scope:DisplayObject;
	/**
	 * Creates a new local mouse location.
	 */
	public function new(x:Float, y:Float, scope:DisplayObject):Void {
		super(x, y);
		// If scope is null, throw an exception. Having null for a scope might produce null object reference errors later on: when
		// the globalLocation property is called.
		if (scope == null) {
			throw "The scope argument must be non-null.";
		}
		this.scope = scope;
	}
	private inline function getGlobalLocation():MouseLocation {
		var globalPoint:Point = scope.localToGlobal(new Point(x, y));
		return new MouseLocation(globalPoint.x, globalPoint.y);
	}
	private override function toString():String {
		return "[LocalMouseLocation x=" + x + " y=" + y + " scope=" + scope + "]";
	}
}